﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;

namespace AISservice.Common
{
    public class AprilConfig
    {
        public static IServiceProvider ServiceProvider;
        public static IConfiguration Configuration;

        public static void InitConfig(IConfiguration _configuration)
        {
            Configuration = _configuration;
        }
        public static HttpContext HttpCurrent
        {
            get
            {
                object factory = ServiceProvider.GetService(typeof(IHttpContextAccessor));
                HttpContext context = ((IHttpContextAccessor)factory).HttpContext;
                return context;
            }
        }


        private static string _IsOpenCache = string.Empty;
        /// <summary>
        /// 是否使用Redis
        /// </summary>
        public static bool IsOpenCache
        {
            get
            {
                if (string.IsNullOrEmpty(_IsOpenCache))
                {
                    _IsOpenCache = Configuration["Redis:IsOpenRedis"];
                }
                if (_IsOpenCache.ToLower() == "true")
                {
                    return true;
                }
                return false;
            }
        }

        private static string _RedisConnectionString = string.Empty;
        /// <summary>
        /// Redis默认连接串
        /// </summary>
        public static string RedisConnectionString
        {
            get
            {
                if (string.IsNullOrEmpty(_RedisConnectionString))
                {
                    _RedisConnectionString = Configuration["Redis:ConnectionString"];
                }
                return _RedisConnectionString;
            }
        }



        private static string _SqlConnectionString = string.Empty;
        /// <summary>
        /// MySql默认连接串
        /// </summary>
        public static string SqlConnectionString
        {
            get
            {
                if (string.IsNullOrEmpty(_SqlConnectionString))
                {
                    _SqlConnectionString = Configuration["DBSetting:ConnectString"];
                }
                return _SqlConnectionString;
            }
        }

        private static string _waittime = string.Empty;
        /// <summary>
        /// MySql默认连接串
        /// </summary>
        public static string Waittime
        {
            get
            {
                if (string.IsNullOrEmpty(_waittime))
                {
                    _waittime = Configuration["waittime:time"];
                }
                return _waittime;
            }
        }


        private static int _safelevel =2;
        /// <summary>
        /// Redis默认连接串
        /// </summary>
        public static int SafeLevel
        {
            get
            {

                 _safelevel =Convert.ToInt32( Configuration["safe:level"]);
                return _safelevel;
            }
        }


    }

}
